<?php
include_once(ROOTDIR."/include/objects/class.User.php");
include_once(ROOTDIR."/include/database/class.UserQueries.php");

$user = new User();
$userQueries = new UserQueries();

$user = $userQueries->getUserInfoById($_GET['id']);

$user->setName(addslashes($_GET['name']));
$user->setEmail($_GET['email']);
$user->setAccessLevel($_GET['accessLevel']);
$user->setSteamId($_GET['steamId']);

$error = "";
if(!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $user->getEmail()) && !$config->enableSmfIntegration) {
  // We don't care if the email is empty
  if($user->getEmail() != "") {
    $error .= "Bad Email Address.  ";
  }
}
if(!preg_match("/^STEAM_[01]:[01]:\d{0,10}$/", $user->getSteamId())) {
  $error .= "Bad Steam ID.  ";
}

// Update if no errors
if($error == "") {
  $userQueries->updateUser($user);
}

// Send back the new active state
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
?>
<?echo "<?xml version=\"1.0\" ?>";?>
<root>
  <id><?=$user->getId()?></id>
	<name><?=$user->getName()?></name>
	<steamid><?=$user->getSteamId()?></steamid>
	<error><?=$error?></error>
</root>
